home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDRemainingTrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  3.1 KB  |  107 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDRemainingTrack - An XFCN to report remaining time on disc
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/11/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDRemainingTrack.c
  11.     link -sn Main=CDRemainingTrack -sn STDIO=CDRemainingTrack ∂
  12.          -sn INTENV=CDRemainingTrack -rt XFCN=42 ∂
  13.          -m CDRemainingTrack CDRemainingTrack.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26.  
  27. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  28.  
  29.  
  30. /************************************************************************
  31.  *
  32.  *  Function:        CDRemainingTrack
  33.  *
  34.  *  Purpose:        return the remaining time on this disc.
  35.  *
  36.  *  Returns:        either 0, or an error
  37.  *                    if it's a negative number, it's an error
  38.  *
  39.  *  Side Effects:
  40.  *
  41.  *  Description:    We need no parameter:
  42.  *                    Get the ioRefNum that we got from previously calling
  43.  *                    CDOpen() by accessing the famous global
  44.  *                    call the driver with a READQ call to find out
  45.  *                    how absolute minute, second, block remaining.
  46.  *
  47.  ************************************************************************/
  48. pascal void
  49. CDRemainingTrack(paramPtr)
  50. XCmdBlockPtr    paramPtr;
  51. {
  52.     Str31    returnString;
  53.     OSErr    result;
  54.     short    ioRefNum;
  55.     Handle    refHandle;
  56.     long    Remaining[4];    /* minute, second, block */
  57.     long    currentMinute, currentSecond, currentBlock;
  58.     long    startMinute, startSecond, startBlock;
  59.     
  60.     /* Must be no parameter */
  61.     if ((paramPtr->paramCount) != 0)
  62.     {
  63.         /* Report error in parameters by returning -1 */
  64.         NumToStr(paramPtr, (long) -1, &returnString);
  65.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  66.         return;
  67.     }
  68.     
  69.     /* Get the global ioRefNum and convert it. */
  70.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  71.     ioRefNum = atoi(*(refHandle));
  72.     DisposHandle(refHandle);
  73.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  74.     
  75.     
  76.     result = ReadQ(ioRefNum, &Remaining[0], ¤tMinute, ¤tSecond, ¤tBlock);
  77.     
  78.     if (result == noErr)
  79.         result = TrackStart(ioRefNum, Remaining[0]+1, &startMinute, &startSecond, &startBlock);
  80.     
  81.     if (result != noErr)    /* we specified an invalid track. Use disc time */
  82.         result = DiscTime(ioRefNum, &startMinute, &startSecond, &startBlock);
  83.         
  84.     if (result == noErr)
  85.     {
  86.         TimeDiff(&Remaining[1], &Remaining[2], &Remaining[3],
  87.                  startMinute, startSecond, startBlock,
  88.                  currentMinute, currentSecond, currentBlock);
  89.     }
  90.  
  91.     if (result == noErr)
  92.     {
  93.         /* convert each value to a string, concatenate, & return. */
  94.         FormatString(&returnString, Remaining, 4);
  95.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  96.     }
  97.     else
  98.     {
  99.         /* We got an error. Convert result to string & return it as error */
  100.         NumToStr(paramPtr, (long) result, &returnString);
  101.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  102.     }
  103. }
  104.  
  105. /* C routines for HyperCard callbacks */
  106. #include <XCmdGlue.inc.c>
  107.